package minidb.type;

import static minidb.type.Const.*;

public class DoubleConstant implements Constant{

	private Double val;
	
	public DoubleConstant(double val){
		this.val = val;
	}
	
	public DoubleConstant(){
		this.val = DOUBLE_NULL;
	}
	
	public Boolean isNull() {
		return val == DOUBLE_NULL;
	}

	public Object toVal() {
		return this.val;
	}

	public int compareTo(Constant val2) {
		if(DoubleConstant.class.isInstance(val2))
			return val.compareTo((Double)(val2.toVal()));
		else
			return val.compareTo(((Integer)val2.toVal()).doubleValue());
	}
	
	public boolean equals(Object obj) {
		DoubleConstant dc = (DoubleConstant) obj;
		return dc != null && val.equals(dc.val);
	}
	
	public int hashCode() {
		return val.hashCode();
	}

	public String toString() {
		return val.toString();
	}

}
